package com.sky.loveshop.controller;

import com.sky.loveshop.entity.OpenDoorHistory;
import com.sky.loveshop.entity.Result;
import com.sky.loveshop.entity.common.PageResult;
import com.sky.loveshop.entity.exception.BizException;
import com.sky.loveshop.entity.exception.BizExceptionEnum;
import com.sky.loveshop.entity.qo.OpenDoorHistoryQO;
import com.sky.loveshop.service.OpenDoorHistoryService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author xcy
 * @version V1.0
 * @description
 * @date 2024/11/4 22:56
 */
@Slf4j
@RestController
@RequestMapping("/openDoorHistory")
public class OpenDoorHistoryController {

    @Autowired
    private OpenDoorHistoryService openDoorHistoryService;

    @PostMapping("/listOpenDoorHistoryPages")
    public Result<PageResult<OpenDoorHistory>> listOpenDoorHistoryPages(@RequestBody OpenDoorHistoryQO qo) {
        return Result.page(openDoorHistoryService.listOpenDoorHistoryPages(qo));
    }

    @GetMapping("/getOpenDoorHistoryById")
    public Result<OpenDoorHistory> getOpenDoorHistoryById(Integer id) throws BizException {
        if (id == null) {
            throw new BizException(BizExceptionEnum.ID_MUST_NEED);
        }
        return Result.success(openDoorHistoryService.getOpenDoorHistoryById(id));
    }

}
